const app = getApp()

Page({
  data: {
    code:'',
    pwd:''
  },
  onLoad: function (t) {
    //app.pageOnLoad(this, t);
    this.setData({
      __user_info:app.core.getStorageSync("USER_INFO")
    })
  },
  onShow: function (t) {
    //app.pageOnShow(this);
    wx.setNavigationBarTitle({
      title: "储值卡",
    })
  },
  submit: function (t) {
    var that = this;
    if (!this.data.code || !this.data.pwd) {
      wx.showToast({
        title: '请补全内容',
        icon: 'none'
      })
      return false;
    }else {
      wx.showLoading({
        title: '提交中',
      })
      app.request({
        url: app.api.svcard.submit,
        data: {
          code: that.data.code,
          pwd: that.data.pwd
        },
        success: function (res) {
          if (res.code > 0) {
            getApp().core.showModal({
              title: "提示",
              content: res.msg,
              showCancel: !1
            })
          }else {
            getApp().core.showModal({
              title: "提示",
              content: res.msg,
              showCancel: !1
            })
            var user_info = that.data.__user_info
            if (res.type == 1) {
              user_info.money = (user_info.money -0) + (res.num - 0)
            }else {
              user_info.integral = (user_info.integral - 0) + (res.num - 0)
            }
            that.setData({
              __user_info: user_info,
              code: '',
              pwd: ''
            })
          }
        },
        fail: function (res) {
          console.log(res);
        },
        complete: function (res) {
          wx.hideLoading();
        }
      })
    }
    
  },
  KeyCode: function (t) {
    this.setData({
      code: t.detail.value
    });
  },
  KeyPwd: function (t) {
    this.setData({
      pwd: t.detail.value
    });
  },
})
